package du.contact2018.dong;

import android.content.pm.PackageManager;
import android.util.Log;


public class UtilBoolean {

    public static final String TAG = Package.getPackages().getClass().getSimpleName();

    ///////////////////////////////////////////////////////////////////

    public static boolean toBoolean(String str) {
        return toBoolean(str, false);
    }

    public static boolean toBoolean(String str, boolean defaultValue) {
        if (UtilString.empty(str))
            return defaultValue;
        try {
            return toRawBoolean(str);
        } catch (Exception e) {
            Log.e(TAG, "toBoolean, failure, str = " + str, e);
            return defaultValue;
        }
    }

//    public static boolean toBooleanFromResource( String key, boolean defaultValue )
//    {
//        String str = ResourceUtil.getResourceString(key);
//        return toBoolean(str, defaultValue);
//    }

    public static boolean toRawBoolean(String str) throws Exception {
        return "true".equalsIgnoreCase(str.trim());
    }

}
